import { useIntersectionObserver, useIntervalFn } from "@vueuse/core"
import { ref } from "vue"
export function useLazyData(callback: () => void) {
  const target = ref(null)
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      // 进入可视区要做的事情 ?
      callback()
      // 停止监视, 以后不会再触发
      stop()
    }
  },{
    threshold: 0
  })
  return target
}

export function useCoundom(count:number){
  const tame = ref(0)
  const {pause,resume} = useIntervalFn(()=>{
         tame.value--
         if(tame.value === 0) pause()

  },1000,{
    immediate:false
  })
  const start = () => {
    tame.value = count
    resume()
  }

  return {
    tame,
    start,
    resume
  }
}